package DAO;

import beans.Order;
import dbutils.DBHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class OrderDaoImpl implements OrderDao {
    @Override
    public void addcOrder(Order order) {
        Connection conn = DBHelper.getConn();
        String sql = "INSERT INTO corders (user, times, name, price, merchant, producer) VALUES (?, ?, ?, ?, ?, ?);";
        PreparedStatement stat = null;
        ResultSet rs = null;
        try {
            stat = conn.prepareStatement(sql);
            stat.setString(1, order.getUser());
            stat.setString(2, order.getTime());
            stat.setString(3, order.getName());
            stat.setString(4, order.getPrice());
            stat.setString(5, order.getMerchant());
            stat.setString(6, order.getProducer());
            stat.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBHelper.closeAll(conn, stat, rs);
        }
    }

}
